// pages/chooseToEmail/chooseToEmail.js
const baseUrl = 'https://gsdse.cn/api/KJRecruit';
const app = getApp();
const db = wx.cloud.database();
const _ = db.command
Page({

  /**
   * 页面的初始数据
   */
  data: {
    timer: '',
    realNameregExp: '',
    usersArray: [],
    openidArray: [],
    departmentName: '网络研发部',
    checkedArray: []
  },
  test() {
    var event = {
      "a": 123
    }
    var {
      leta
    } = event
    console.log(leta);
  },
  gotoSendEmail() {
    console.log(this.data.checkedArray);
    if (this.data.checkedArray != '') {
      wx.navigateTo({
        url: '/pages/sendEmail/sendEmail?' + "checkedArray=" + JSON.stringify(this.data.checkedArray)
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '你还没选择用户'
      })
    }

  },
  addUser(event) {
    console.log(event);
    var person = event.currentTarget.dataset.item
    console.log(person);
    this.setData({
      checkedArray: this.data.checkedArray.concat(person)
    })

  },
  deleteUser(event) {
    var index = event.target.dataset.index
    console.log(index);
    var oldArray = this.data.checkedArray
    oldArray.splice(index, 1)
    this.setData({
      checkedArray: oldArray
    })
  },
  searchApplication(e) {
    //防抖处理
    clearTimeout(this.timer)
    this.timer = setTimeout(() => {
      //先对数组进行清空
      this.setData({
        usersForm: [],
      })
      var inputValue = e.detail.value
      console.log(e.detail.value)
      var realNameregExp = '.*'
      //搜索名字不为初始值则构建正则
      if (inputValue != '') {
        for (let i = 0; i < inputValue.length; i++) {
          realNameregExp = realNameregExp + '.*' + inputValue.charAt(i) + "+"
        }
        console.log("构建后的正则" + realNameregExp)
        this.setData({
          realNameregExp: realNameregExp
        })
        // this._queryUserslist();
        this.getPersonInfo();
      } else {
        this.setData({
          usersArray: []
        })
      }


    }, 1500);
  },
  getPersonInfo() {
    console.log(this.data.realNameregExp);
    console.log(this.data.openidArray);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

})